<template>
	<view class="content">
		<form action="">
			标题:<input type="text" v-model="title" />
			内容:<input type="text" v-model="content" />
			<button @click="add">发布</button>
		</form>
		<table>
			<tr>
				<td>编号</td>
				<td>标题</td>
				<td>内容</td>
			</tr>
			<tr v-for="v in list">
				<td>{{v.ID}}</td>
				<td>{{v.title}}</td>
				<td>{{v.content}}</td>
				<td><button @click="del(v.ID)">删除</button></td>
			</tr>
		</table>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title:"",
				content:"",
				list:[],
				page:1,
				size:3,
			}
		},
		onLoad() {
			this.li()
		},
		methods: {
			li(){
				uni.request({
				    url: 'http://127.0.0.1:8000/list', //仅为示例，并非真实接口地址。
				    data: {
				        // text: 'uni.request'
						page:this.page,
						size:this.size,
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
				        this.list = res.data.data
				    }
				});
			
			},
			add(){
				uni.request({
					method:'POST',
				    url: 'http://127.0.0.1:8000/add', //仅为示例，并非真实接口地址。
				    data: {
				        title:this.title,
						content:this.content,
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
				        this.text = 'request success';
						alert("发布成功")
				    }
				});
			},
			del(id){
				uni.request({
					method:'POST',
				    url: 'http://127.0.0.1:8000/del', //仅为示例，并非真实接口地址。
				    data: {
				       id:id,
				    },
				    header: {
				        'content-type': 'application/x-www-form-urlencoded ' //自定义请求头信息
				    },
				    success: (res) => {
				        console.log(res.data);
				        this.text = 'request success';
				    }
				});

			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
